#
# Auto dependency for binary
#

CFLAGS += -fstack-protector-all
ifndef SRCS
SRCS    := $(wildcard *.c)
endif
OBJS    := $(SRCS:%.c=%.o)

.PHONY:	clean strip all


ifdef COPY_TO_DIR
all: $(COPY_TO_DIR)/$(TARGET_BIN)

$(COPY_TO_DIR)/$(TARGET_BIN): $(TARGET_BIN)
	$(MKDIR) -p $(COPY_TO_DIR)
	$(CP) $< $(COPY_TO_DIR)
endif

$(TARGET_BIN): $(OBJS) $(LIB_DEPEND)
	@$(ECHO) Compiling $@, changed dep:$?
	@$(RM) $(TARGET_BIN)*.map
	$(CC) -o $@ $(OBJS) $(CFLAGS) $(LD_FLAGS)
ifneq ($(DEBUG), y)
	$(STRIP) -S $(TARGET_BIN)
endif
	@$(ECHO)  "==========Excutable binary" $@ "Build OK ==========" 

clean:
	@$(RM) $(MAKE_LOG_FILE)
	@$(RM) $(DEPEND_FILE_NAME)
	@$(RM) $(TARGET_BIN)*.map
	@$(RM) $(TARGET_BIN)
	@$(RM) $(OBJS)
ifdef COPY_TO_DIR
	$(RM) $(COPY_TO_DIR)/$(TARGET_BIN)
endif

strip:
	$(STRIP) -S $(TARGET_BIN)

$(DEPEND_FILE_NAME):$(SRCS)
	$(RM)	$@
	for x in $(SRCS);	\
	do			\
		$(CC) -MM -MT"$${x%.c}.o" $(CFLAGS) $$x >> $@;\
	done			

include $(SPLINT_MK)

include $(BUILD_MK)

ifneq "$(MAKECMDGOALS)" "clean"
sinclude $(DEPEND_FILE_NAME)
endif

# vim:noet:sw=4:ts=4

